package com.rr.security.filter;

import com.rr.security.AuthTokenManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author RR
 * @date 2023/3/15 23:06
 */
public class MyLogoutHandler implements LogoutHandler {

    private AuthTokenManager authTokenManager;

    public MyLogoutHandler(AuthTokenManager authTokenManager) {
        this.authTokenManager = authTokenManager;
    }

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            authTokenManager.remove(token);
            System.out.println("删除token:" + token);
        }
    }
}
